package com.gtr.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gtr.entity.VaccinumCategory;
import com.gtr.entity.VaccinumInfo;
import com.gtr.mapper.VaccinumCategoryMapper;
import com.gtr.mapper.VaccinumInfoMapper;
import com.gtr.service.VaccinumCategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gtr.vo.BuyerVaccinumCategoryVO;
import com.gtr.vo.BuyerVaccinumInfoVO;
import com.gtr.vo.SellerVaccinumCategoryVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 类目表 服务实现类
 * </p>
 *
 * @author gtr
 * @since 2023-02-27
 */
@Service
public class VaccinumCategoryServiceImpl extends ServiceImpl<VaccinumCategoryMapper, VaccinumCategory> implements VaccinumCategoryService {

    @Autowired
    private VaccinumCategoryMapper vaccinumCategoryMapper;
    @Autowired
    private VaccinumInfoMapper vaccinumInfoMapper;

    @Override
    public List<BuyerVaccinumCategoryVO> buyerList() {
        List<VaccinumCategory> vaccinumCategoryList = this.vaccinumCategoryMapper.selectList(null);
        List<BuyerVaccinumCategoryVO> result = new ArrayList<>();
        for(VaccinumCategory vaccinumCategory : vaccinumCategoryList){
            BuyerVaccinumCategoryVO vo = new BuyerVaccinumCategoryVO();
            vo.setName(vaccinumCategory.getCategoryName());
            vo.setType(vaccinumCategory.getCategoryType());
            QueryWrapper<VaccinumInfo> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("category_type", vaccinumCategory.getCategoryType());
            List<VaccinumInfo> vaccinumInfoList = this.vaccinumInfoMapper.selectList(queryWrapper);
            List<BuyerVaccinumInfoVO> productInfoVOS = new ArrayList<>();
            for(VaccinumInfo vaccinumInfo : vaccinumInfoList){
                BuyerVaccinumInfoVO vo1 = new BuyerVaccinumInfoVO();
                BeanUtils.copyProperties(vaccinumInfo, vo1);
                productInfoVOS.add(vo1);
            }
            vo.setGoods(productInfoVOS);
            result.add(vo);
        }
        return result;
    }

    @Override
    public List<SellerVaccinumCategoryVO> sellerList() {
        List<VaccinumCategory> vaccinumCategoryList = this.vaccinumCategoryMapper.selectList(null);
        List<SellerVaccinumCategoryVO> sellerVaccinumCategoryVOList = new ArrayList<>();
        for (VaccinumCategory vaccinumCategory : vaccinumCategoryList) {
            SellerVaccinumCategoryVO vo = new SellerVaccinumCategoryVO();
            vo.setName(vaccinumCategory.getCategoryName());
            vo.setType(vaccinumCategory.getCategoryType());
            sellerVaccinumCategoryVOList.add(vo);
        }
        return sellerVaccinumCategoryVOList;
    }
}
